package com.hymall.bean.bo;

import com.hymall.bean.MarketGoods;
import com.hymall.bean.MarketGoodsAttribute;
import com.hymall.bean.MarketGoodsProduct;
import com.hymall.bean.MarketGoodsSpecification;
import com.hymall.bean.vo.Product2;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.util.LinkedList;
import java.util.List;

/**
 * @Author: haiyuny
 * @Date: 2022/7/18 17:08
 * @Description:
 */
@Data
public class AddGoodBO {
    private MarketGoods goods;
    private List<MarketGoodsAttribute> attributes;
    private List<MarketGoodsSpecification> specifications;
    private List<Product2> products;

    public List<MarketGoodsProduct> change() {
        if (products == null) {
            return null;
        }
        LinkedList<MarketGoodsProduct> list = new LinkedList<>();
        for (Product2 product : products) {
            MarketGoodsProduct marketGoodsProduct = new MarketGoodsProduct();
            BeanUtils.copyProperties(product,marketGoodsProduct,"specifications");
            marketGoodsProduct.setSpecifications(product.getSpecifications());

            list.add(marketGoodsProduct);
        }
        return list;
    }
}
